import cv2
import numpy as np
import matplotlib.pyplot as plt

gray = cv2.imread("img/landscape.png", 0)

x = np.arange(0, 256, dtype=np.int32)
y = np.zeros((256,), dtype=np.int32)
h,w = gray.shape

for i in range(h):
    for j in range(w):
        y[gray[i,j]] += 1

plt.plot(x,y,'r-')
plt.show()